/*
 * Copyright (C) 2013  Richard Schilling. All rights reserved.
 * contact: coderroadie@gmail.com
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package android.persist.op;

import java.util.Map;
import java.util.Map.Entry;

/**
 * {@code Count} classes that count the number of persisted classes.
 * 
 * @author Richard Schilling (coderroadie@gmail.com)
 * @since 1.0
 */
public abstract class Count<OT, RT> extends OrmOperation<OT, RT> {
    /**
     * If mCriteria is null then it should be ignored by the extending class. If
     * it is not null then the values in the map should be utilized to select
     * criteria using an equals operator.
     */
    protected final Map<String, Object> mCriteria;

    /**
     * Creates a new read operation.
     * 
     * @param o becomes {@link OrmOperation#operand}.
     * @param criteria an optional parameter that contains selection criteria.
     * @throws IllegalArgumentException if any key value of {@code criteria} is
     *             null.
     */
    public Count(OT o, Map<String, Object> criteria) {
        super(o);

        this.mCriteria = criteria;
        if (this.mCriteria != null) {

            for (Entry<String, Object> entry : this.mCriteria.entrySet()) {

                String key = entry.getKey();
                if (key == null) {
                    throw new IllegalArgumentException("parameter keys has a null key value");
                }

            }

        }
    }

}
